﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.ProfessionalTeam.DAL;

public partial class MapInfo_ProfessionalTeam_ProcNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.UrlReferrer != null)
            {
                ViewState["UrlReferrer"] = Request.UrlReferrer;
            }
            BindType();

            init();
        }
    }

    void BindType()
    {
        TeamDataContext tdc = new TeamDataContext();
        ddlProcessionType.DataSource = tdc.ProcsType;
        ddlProcessionType.DataBind();
    }

    void init()
    {

        if (Request["Pid"] != null)
        {
            TeamDataContext tdc = new TeamDataContext();
            ProfessionalProc proc = tdc.ProfessionalProc.Where(o => o.id == new Guid(Request["Pid"])).FirstOrDefault<ProfessionalProc>();
            txtFunction.Text = proc.ProcessionFunction;
            ddlProcessionType.SelectedValue = proc.ProcessionType.ToString();
        }
    }

    //添加
    protected void butOk_Click(object sender, EventArgs e)
    {
        try
        {
            if (Request["Pid"] == null)
            {
                TeamDataContext tdc = new TeamDataContext();
                string DepartmentId = Request["DepartmentId"];
                ProfessionalProc proc = new ProfessionalProc();
                proc.id = Guid.NewGuid();
                proc.ProcessionFunction = txtFunction.Text;
                proc.ProcessionType =Convert.ToInt32( ddlProcessionType.SelectedValue);
                proc.SerUpdateDate = DateTime.Now;
                proc.SetUserId = User.Identity.Name;
                proc.DepartmentId = Request["DepartmentId"];
                tdc.ProfessionalProc.InsertOnSubmit(proc);
                tdc.SubmitChanges();
            }
            else
            {
                TeamDataContext tdc = new TeamDataContext();
                ProfessionalProc proc = tdc.ProfessionalProc.Where(o => o.id == new Guid(Request["Pid"])).FirstOrDefault<ProfessionalProc>();
                proc.ProcessionFunction = txtFunction.Text;
                proc.ProcessionType = Convert.ToInt32(ddlProcessionType.SelectedValue);
                proc.SerUpdateDate = DateTime.Now;
                proc.SetUserId = User.Identity.Name;

                tdc.SubmitChanges();
            }
            Prompt.Text = "提示：保存成功！";
        }
        catch
        {
            Prompt.Text = "提示：保存失败！";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("ProfessionalProc.aspx?DepartmentId=" + Request["DepartmentId"]);
    }

    protected void lblReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect(ViewState["UrlReferrer"].ToString());
    }
}
